package gui;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

import javax.swing.JComponent;
import javax.swing.JPanel;

/**
 * Gestiona la composicion y organizacion de elementos graficos en los paneles.
 * 
 * @author age, joaquinmonleon
 *
 */
public class Layout {

	// Antes de invocar addItem se de establecer el layout del panel con el devuelto aqui
	public static GridBagLayout getLayout () {
		return new GridBagLayout();
	}
	
	public static void addItem (int y, int x, JPanel p, JComponent c) {
		addItem (y, x, p, c, 
				GridBagConstraints.CENTER, 
				GridBagConstraints.BOTH,
				1, 1, 10.0, 10.0, 2
			);
	}
	
	public static void addItem (int y, int x, JPanel p, JComponent c, int anchor, int fill) {
		addItem (y, x, p, c, 
				anchor, 
				fill,
				1, 1, 10.0, 10.0, 2
			);
	}

	public static void addItem (int y, int x, JPanel p, JComponent c, int anchor, int fill, int gridwidth, int gridheight) {
		addItem (y, x, p, c, 
				anchor, 
				fill,
				gridwidth, 1, 10.0, 10.0, 2
			);
	}
	
	public static void addItem (int y, int x, JPanel p, JComponent c, int anchor, int fill, int gridwidth, int gridheight, double weightx, double weighty, int insets) {
	    GridBagConstraints gc = new GridBagConstraints();
	    gc.gridx = x;
	    gc.gridy = y;
	    gc.gridwidth = gridwidth;
	    gc.gridheight = gridheight;
	    gc.weightx = weightx;
	    gc.weighty = weightx;
	    gc.insets = new Insets(insets, insets, insets, insets);
	    gc.anchor = anchor;
	    gc.fill = fill;
	    p.add(c, gc);
	}
}
